package com.csust.reflection.qusetion;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Properties;

public class ReflectionQusetion {
    public static void main(String[] args) throws Exception {
        //通过properties文件里面得内容 创建Cat对象 并且调用方法method（hi方法）
        Properties props = new Properties();
        props.load(new FileInputStream("D:\\Work\\Backend\\JAVA\\Coding\\WorkSpace\\javase\\module-17-reflection-review\\src\\re.properties"));


        String className = props.get("className").toString();//con.csust.Cat
//        System.out.println(className);
        String methodName = props.get("method").toString();//hi
//        System.out.println(methodName);


//
        Class aClass = Class.forName(className);
        Object o = aClass.newInstance();
        Method method = aClass.getMethod(methodName);


        method.invoke(o);


//        Field field = aClass.getField("name");
//        field.setAccessible(true);
//        System.out.println(field.get(o));

        Field field2 = aClass.getField("age");
        System.out.println(field2.get(o));


    }
}
